<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <textarea name="" id=""></textarea>
  <button class="">提交</button>
  <h1>消息列表</h1>
  <div class="list">
    <span>默认的消息</span>
  </div>
  <button class="box">删除节点</button>

  <script>
    const textarea = document.querySelector('textarea')
    const botton = document.querySelector('button')
    const h1 = document.querySelector('h1')
    const list = document.querySelector('.list')

    botton.addEventListener('click', () => {
      const message = textarea.value.trim()

      const newP = document.createElement("p")

      newP.innerText = message
      list.append(newP)

      newP.addEventListener('click', () => {
        newP.remove()
      })

      //document.body.append(newP)
    })
    // const box = document.querySelector('.box')
    // box.addEventListener('click', () => {
    //   const p = document.querySelector('p')
    //   p.remove()
    // })
  </script>
</body>

</html>